load(
    "//tools/skylark:pybind.bzl",
    "get_pybind_package_info",
)
load(
    "//tools/skylark:drake_py.bzl",
    "drake_py_library",
    "drake_py_unittest",
)
load(
    "//tools/skylark:pybind.bzl",
    "drake_pybind_library",
)
load("//bindings/pydrake:pydrake.bzl", "add_lint_tests_pydrake")

package(default_visibility = [
    "//bindings/pydrake:__subpackages__",
])

# This determines how `PYTHONPATH` is configured.
PACKAGE_INFO = get_pybind_package_info("//bindings")

drake_py_library(
    name = "module_py",
    testonly = 1,
    srcs = ["__init__.py"],
    imports = PACKAGE_INFO.py_imports,
    deps = [
        "//bindings/pydrake/common",
    ],
)

drake_py_library(
    name = "algebra_test_util_py",
    testonly = True,
    srcs = ["algebra_test_util.py"],
    visibility = [
        "//bindings/pydrake/autodiffutils:__pkg__",
        "//bindings/pydrake/symbolic:__pkg__",
    ],
    deps = [
        ":module_py",
    ],
)

drake_pybind_library(
    name = "autodiffutils_test_util_py",
    testonly = True,
    add_install = False,
    cc_deps = [
        "//bindings/pydrake:autodiff_types_pybind",
        "//bindings/pydrake:documentation_pybind",
    ],
    cc_so_name = "autodiffutils_test_util",
    cc_srcs = ["autodiffutils_test_util_py.cc"],
    package_info = PACKAGE_INFO,
)

drake_py_library(
    name = "deprecation_py",
    testonly = 1,
    srcs = ["deprecation.py"],
    deps = [":module_py"],
)

drake_py_library(
    name = "meta_py",
    testonly = 1,
    srcs = ["meta.py"],
    deps = [":module_py"],
)

drake_py_unittest(
    name = "meta_test",
    deps = [
        ":meta_py",
    ],
)

drake_py_library(
    name = "numpy_compare_py",
    testonly = 1,
    srcs = ["numpy_compare.py"],
    deps = [
        ":module_py",
        "//bindings/pydrake:polynomial_py",
    ],
)

drake_py_library(
    name = "pickle_compare_py",
    testonly = 1,
    srcs = ["pickle_compare.py"],
    deps = [
        ":module_py",
        ":numpy_compare_py",
    ],
)

# A library that force-disables scipy, even if it's installed system-wide.
drake_py_library(
    name = "scipy_none_py",
    testonly = 1,
    srcs = [
        "scipy_none/scipy/__init__.py",
    ],
    # N.B. We do not depend on ":module_py".
    imports = ["scipy_none"],
)

# A minimal of implementation scipy.sparse that's barely functional enough
# to support unit testing the Drake APIs that return Eigen::Sparse matrices.
# The pybind11 type caster for Eigen::Sparse maps it to scipy.sparse.
drake_py_library(
    name = "scipy_stub_py",
    testonly = 1,
    srcs = [
        "scipy_stub/scipy/__init__.py",
        "scipy_stub/scipy/sparse/__init__.py",
    ],
    # N.B. We do not depend on ":module_py".
    imports = ["scipy_stub"],
)

# Package roll-up (for Bazel dependencies).
drake_py_library(
    name = "test_utilities",
    testonly = 1,
    deps = [
        ":deprecation_py",
        ":module_py",
        ":numpy_compare_py",
        ":pickle_compare_py",
        # N.B. Do not add algebra_test_util_py here; it should be scoped to
        # only very specific tests that need it.
        # N.B. Do not add scipy_stub_py here; it inserts scipy as a top-level
        # module. Developers should only do that with intent, not as a bonus
        # dependency from a conveience roll-up module.
    ],
)

add_lint_tests_pydrake()
